package cn.spring.service.impl;

import cn.spring.base.utils.PageInfo;
import cn.spring.domain.Department;
import cn.spring.domain.Employee;
import cn.spring.mapper.DepartmentMapper;
import cn.spring.query.DepartmentQuery;
import cn.spring.service.IDepartmentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import javax.swing.*;
import java.util.List;
@Service
@Transactional(propagation = Propagation.SUPPORTS,readOnly = true)
public class IDepartmentServiceImpl implements IDepartmentService {

    @Autowired
    private DepartmentMapper departmentMapper;

    @Transactional
    @Override
    public void insert(Department department) {
        departmentMapper.insert(department);
    }
    @Transactional
    @Override
    public void update(Department department) {
        departmentMapper.update(department);
    }
    @Transactional
    @Override
    public void delete(Long id) {
        departmentMapper.delete(id);
    }

    @Override
    public List<Department> selectAll() {
        return departmentMapper.selectAll();
    }

    @Override
    public Department selectById(Long id) {
        return departmentMapper.selectById(id);
    }

    @Override
    public void batchDelete(List<Long> ids) {
        departmentMapper.batchDelete(ids);
    }

    @Override
    public PageInfo<Department> queryPage(DepartmentQuery departmentQuery) {
        PageInfo<Department> objectPageInfo = new PageInfo<>();
        Long total = departmentMapper.queryTotal(departmentQuery);
            if (total != 0){
                List<Department> list =  departmentMapper.queryPage(departmentQuery);
                 objectPageInfo.setList(list);
                objectPageInfo.setTotal(total);
            }
            return objectPageInfo;
    }
}
